services:
  nginx:
    image: nginx:1.23.1
    container_name: nginx
    restart: unless-stopped
    networks:
      server_network:
    volumes:
      - /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - /etc/nginx/sites-available/:/etc/nginx/sites-available/:ro
      - /etc/nginx/sites-enabled/:/etc/nginx/sites-enabled/:ro
      - /etc/nginx/mime.types:/etc/nginx/mime.types:ro
      - /etc/certbot/:/etc/nginx/ssl/:ro
      - /srv/www/:/srv/www/:ro
      - /var/log/nginx/:/var/log/nginx/:rw
      - /var/www/certbot/:/var/www/certbot/:ro
    ports:
      - 80:80
      - 443:443
    logging:
      driver: 'json-file'
      options:
        max-file: '1'
        max-size: '1m'
    command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
  certbot:
    image: certbot/certbot:v1.30.0
    container_name: certbot
    restart: unless-stopped
    networks:
      server_network:
    volumes:
      - /var/www/certbot/:/var/www/certbot/:rw
      - /etc/certbot/:/etc/letsencrypt/:rw
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

networks:
  server_network:
    external: true
